<template>
  <el-dialog width="500px" :title="dialogTitle" :visible.sync="dialogVisible" :close-on-click-modal="false">
    <el-form ref="ruleForm" :model="form" :rules="rules" label-width="100px">
      <el-form-item label="订单编号">
        <el-input v-model="form.orderId" disabled />
      </el-form-item>
      <!-- <el-form-item label="备注类型">
        <el-select v-model="form.type" filterable placeholder="请选择备注类型" @change="changeType">
          <el-option v-for="item in typeList" :key="item.type" :label="item.name" :value="item.type" />
        </el-select>
      </el-form-item> -->
      <el-form-item label="备注" prop="remark">
        <el-input v-model="form.remark" type="textarea" :rows="4" placeholder="备注" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size="small" @click="dialogVisible = false">取 消</el-button>
      <el-button size="small" type="primary" @click="submit">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { setOrderRemark } from '@/api/order'
export default {
  // props: ['orderId'],
  props: {
    orderId: {
      type: String,
      default: ''
    },
    dialogTitle:{
      type: String,
      default: ''
    }
  },
  data() {
    return {
      form: {
        orderId: '',
        remark: '',
        type:''
      },
      typeList:[
        {
          type:1,
          name:'风控备注'
        },
        {
          type:9,
          name:'其他备注'
        }
      ],
      rules: {
        remark: [
          { required: true, message: '备注不能为空', trigger: 'blur' }
        ]
      },
      dialogVisible: false
    }
  },
  watch: {
    dialogVisible(val) {
      if (val) {
        this.form.orderId = this.orderId
        this.form.remark = ''
      } else {
        this.$refs['ruleForm'].resetFields()
      }
    }
  },
  methods: {
    submit() {
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          if(this.dialogTitle=='风控建议'){
            this.form.type='1'
          }else{
            this.form.type='9'
          }
          setOrderRemark({ ...this.form }).then(res => {
            this.dialogVisible = false
            this.$emit('getList', true)
          })
        } else {
          this.$message({
            message: '请检查表单错误',
            type: 'error'
          })
          return false
        }
      })
    },
    changeType(item){
      this.form.type=item
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
